package com.youlai.boot.system.controller;

import com.youlai.boot.common.result.Result;
import com.youlai.boot.common.result.ResultCode;
import com.youlai.boot.system.model.QB.Intertill;
import com.youlai.boot.system.model.QB.Wintering;
import com.youlai.boot.system.service.WinteringService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.ParameterResolutionDelegate;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("api/v1/winter")
public class WinteringController {
    /**
     * 越冬保护SMP
     */

    @Autowired
    private WinteringService winteringService;



    @PostMapping("/save")
    public Result<?> saveConstruct(@RequestBody Wintering wintering){
        return Result.judge(winteringService.saveWintering(wintering),"添加成功","添加失败");
    }
    @PostMapping("/all")
    public Result<List<Wintering>> getAllConstruct(){
        List<Wintering> constructs = winteringService.getAllWintering();
        Result<List<Wintering>> result;
        if (!constructs.isEmpty()){
            result = Result.success(constructs);
            result.setMessage("查询成功");
            result.setCode(ResultCode.SUCCESS.getCode());
        }
        else {
            result=Result.failed(ResultCode.SYSTEM_EXECUTION_ERROR);
            result.setMessage("查询失败");
        }
        return result;
    }
    @DeleteMapping("{id}")
    public  Result<?> deleteConstructById(@PathVariable Integer id ){
        return Result.judge(winteringService.deleteWinteringById(id),"删除成功","删除失败");
    }
}
